<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    {{ template  "link/customer/link.html" .}}
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <style>
        #goodpic {
            width: 350px;
            height: 350px;
        }
    </style>
</head>

<body>

{{template "link/customer/nav.html" .}}


<div class="header">
    <div class="headerLayout w1200">
        <div class="headerCon">
            <h1 class="mallLogo">
                <a href="#" title="母婴商城">
                    <img src="/static/img/logo.png">
                </a>
            </h1>
            <div class="mallSearch">
                <form action="" class="layui-form" novalidate>
                    <input type="text" name="title" required lay-verify="required" autocomplete="off"
                           class="layui-input" placeholder="请输入需要的商品">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">
                        <i class="layui-icon layui-icon-search"></i>
                    </button>
                    <input type="hidden" name="" value="">
                </form>
            </div>
        </div>
    </div>
</div>


<div class="content content-nav-base datails-content">
    <div class="main-nav">
        <div class="inner-cont0">
            <div class="inner-cont1 w1200">
                <div class="inner-cont2">
                    <a href="#" class="active">所有商品</a>
                    <a href="#">今日团购</a>
                    <a href="#">母婴资讯</a>
                    <a href="#">关于我们</a>
                </div>
            </div>
        </div>
    </div>
    <div class="data-cont-wrap w1200">
        <div class="crumb">
            <a href="javascript:;">首页</a>
            <span>></span>
            <a href="javascript:;">所有商品</a>
            <span>></span>
            <a href="javascript:;">产品详情</a>
        </div>
        <div class="product-intro layui-clear">
            <div class="preview-wrap">
                <a href="javascript:;"><img id="goodpic" src="/static/upload/good/{{.Good.GoodUrl}}"></a>
            </div>
            <div class="itemInfo-wrap">
                <div class="itemInfo">
                    <div class="title">
                        <h4>{{.Good.GoodName}} </h4>
                        <input type="text" hidden="hidden" value="{{.Good.GoodId}}" id="goodId">
                        <input type="text" hidden="hidden" value="{{.Good.GoodStoreId}}" id="storeId">
                        <span><i class="layui-icon layui-icon-rate-solid"></i>收藏</span>
                    </div>
                    <div class="summary">
                        <p class="reference"><span>参考价</span>
                            <del>{{.Good.GoodRefPrices}}</del>
                        </p>
                        <p class="activity"><span>活动价</span><strong class="price"><i>￥</i>{{.Good.GoodPrices}}</strong>
                        </p>
                        <input type="text" id="prices" value="{{.Good.GoodPrices}}" hidden="hidden  ">
                        <p class="address-box">
                            <span>送&nbsp;&nbsp;&nbsp;&nbsp;至</span>
                            {{if .Address }}
                                <strong class="address">{{.Address}}</strong>
                            {{else}}
                                <strong class="address">北京 &nbsp; &nbsp;&nbsp;&nbsp;东湖区</strong>
                            {{end}}
                        </p>
                    </div>
                    <div class="choose-attrs">
                        <div class="number layui-clear"><span class="title">数&nbsp;&nbsp;&nbsp;&nbsp;量</span>
                            <div class="number-cont"><span class="cut btn">-</span><input
                                        onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
                                        onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
                                        maxlength="4" type="" name="" value="1" id="shopNum"><span
                                        class="add btn">+</span> <span
                                        style="margin-left: 20px">剩  余({{.Good.GoodStorage}})</span></div>
                        </div>


                    </div>
                    <div class="choose-btns">
                        <button class="layui-btn layui-btn-primary purchase-btn" id="buy-now">立刻购买</button>
                        <button class="layui-btn  layui-btn-danger car-btn" id="addBtn"><i
                                    class="layui-icon layui-icon-cart-simple"></i>加入购物车
                        </button>
                    </div>
                </div>
            </div>
        </div>
        <div class="detail-info">
            <div>商品简介:</div>
            <br>
            <textarea class="layui-textarea" name="" style="width: 100%; height: auto"
                      disabled="disabled">{{.Good.GoodDescription}}</textarea>
        </div>
    </div>

</div>
<script type="text/javascript">
    layui.config({
        base: '/static/js/util/' //你存放新模块的目录，注意，不是layui的模块目录
    }).use(['mm', 'jquery', 'layer'], function () {
        var mm = layui.mm, $ = layui.jquery;
        var cur = $('.number-cont input').val();
        var layer = layui.layer

        $("#buy-now").on('click',function () {
            layer.open({
                    content: '是否购买',
                    yes: function () {
                        var number = $("#shopNum").val()
                        var goodId = $("#goodId").val()
                        var prices = $("#prices").val()
                        var storeId = $("#storeId").val()
                        var ItemNums = '"ItemNums":' + number;
                        var ItemPrices = '"ItemPrices":' + prices;
                        var ItemGoodsId = '"ItemGoodsId":' + goodId;
                        var storeId = '"ItemStoreId":' + storeId;
                        var item = "item={" + ItemNums + "," + ItemPrices + "," + ItemGoodsId  + "," + storeId + "}"
                        $.ajax({
                                url: "/customer/orderNow",
                                method: 'post',
                                data: item,
                                dataType: 'json',
                                contentType: "application/x-www-form-urlencoded;charset=UTF-8",
                                success: function (res) {
                                    console.log(res);
                                    if (res.Code == 0) {
                                        $(location).attr('href', '/customer/orderEx?'+res.Data.url);
                                    } else {
                                        layer.alert("购买失败")
                                    }
                                }
                            }
                        )
                    }
                }
            )
        })
        $("#addBtn").on('click', function () {
            var number = $("#shopNum").val()
            var goodId = $("#goodId").val()
            var prices = $("#prices").val()
            var datapost = 'shopNum=' + number + '&goodId=' + goodId + '&prices=' + prices + ''

            console.log(datapost);
            $.ajax({
                    url: "/customer/shopcart",
                    method: 'post',
                    data: datapost,
                    dataType: 'json',
                    contentType: "application/x-www-form-urlencoded;charset=UTF-8",
                    success: function (res) {
                        console.log(res);
                        if (res.Code == 0) {
                            layer.alert("添加成功")
                        } else {
                            layer.alert("添加失败")
                        }
                    }
                }
            )
        })

        $('.number-cont .btn').on('click', function () {
            if ($(this).hasClass('add')) {
                if (cur <{{.Good.GoodStorage}}) {
                    cur++;
                }

            } else {
                if (cur > 1) {
                    cur--;
                }

            }
            $('.number-cont input').val(cur)
        })

    });
</script>
</body>
</html>